Skip to content

Fix Kotlin/JS publish: expect/actual for MetadataKey identifier#218

Merged
isaac-udy merged 1 commit into
mainfrom
fix-metadata-key-js
May 25, 2026
Merged

Fix Kotlin/JS publish: expect/actual for MetadataKey identifier#218
isaac-udy merged 1 commit into
mainfrom
fix-metadata-key-js

Conversation

@isaac-udy

Copy link
Copy Markdown
Owner

Summary

./gradlew publishToMavenLocal was failing with:

e: …/enro-common/src/commonMain/kotlin/dev/enro/NavigationKey.kt:227:25
This reflection API is not supported in Kotlin/JS.

enro-common targets Kotlin/JS (so a NodeJS backend can reference NavigationKey types) but the inner MetadataKey.name was using this::class.qualifiedName, which K/JS refuses at compile time. The code happened to compile on every other target so this only surfaced at publish.

Fix

Internal expect fun metadataKeyName(kClass) in commonMain, with actuals per source set:

Source set Implementation
androidMain / desktopMain / iosMain / wasmJsMain qualifiedName (with a defensive simpleName fallback)
jsMain simpleName only β€” with a doc comment explaining the cross-package collision risk and why the object MyKey : MetadataKey<…> pattern stays safe

Verified

  • ./gradlew :enro-common:publishToMavenLocal β€” succeeds across all five targets (was: failing on JS compile)
  • ./gradlew :enro-common:compileKotlinJs / compileKotlinDesktop / compileKotlinIosSimulatorArm64 / compileKotlinWasmJs β€” all green
  • ./gradlew :enro-runtime:desktopTest β€” full suite still green

Test plan

  • ./gradlew :enro-common:publishToMavenLocal β€” JS target compiles and publishes.
  • ./gradlew publishToMavenLocal (full project) β€” confirm the original beta-publish-prep run finishes without the K/JS error.
  • Spot-check generated POM in ~/.m2/repository/dev/enro/enro-common/3.0.0-beta01/ β€” looks normal, includes the JS variant.

πŸ€– Generated with Claude Code

enro-common targets Kotlin/JS (for non-UI KMP scenarios like a NodeJS
backend), and Kotlin/JS reflection deliberately refuses qualifiedName at
compile time. NavigationKey.MetadataKey.name was using
this::class.qualifiedName from commonMain, which compiled on every
other target but stopped publishToMavenLocal in its tracks with:

    e: …/NavigationKey.kt:227:25
    This reflection API is not supported in Kotlin/JS.

The reflection call is now an internal expect fun metadataKeyName(kClass)
in commonMain, with actuals per source set:

- androidMain / desktopMain / iosMain / wasmJsMain β€” qualifiedName, with
  a simpleName fallback for the defensive case.
- jsMain β€” simpleName only (with a doc comment explaining the
  cross-package collision risk and why the common
  `object MyKey : MetadataKey<…>` pattern stays safe).

Verified `./gradlew :enro-common:publishToMavenLocal` succeeds on all
five targets, and `:enro-runtime:desktopTest` still green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@isaac-udy isaac-udy merged commit f02a057 into main May 25, 2026
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant